home *** CD-ROM | disk | FTP | other *** search
- #include <MacIncludes.h>
-
- extern Boolean gHaveAUX;
-
- #define hide 1
- #define show 0
-
- struct ClipStack {
- RgnHandle Clip;
- struct ClipStack *Next;
- } *TheStacks[2];
-
-
- void PushClip(int stack)
- {
- struct ClipStack *node;
-
- node = (struct ClipStack *)NewPtr(sizeof(struct ClipStack));
- node -> Clip = NewRgn();
- GetClip(node->Clip);
- node -> Next = TheStacks[stack];
- TheStacks[stack] = node;
- }
-
- void PopClip(int stack)
- {
- struct ClipStack *node;
-
- if(TheStacks[stack]){
- SetClip(TheStacks[stack]->Clip);
- DisposeRgn(TheStacks[stack]->Clip);
- node = TheStacks[stack]->Next;
- DisposPtr((Ptr)TheStacks[stack]);
- TheStacks[stack] = node;
- } else {
- char debug[100];
- sprintf(debug,"Stack underflow in PopClip, called with stack %d",stack);
- debugstr(debug);
- }
- }
-
- void EnableDItem(DialogPtr dialog, short item, short state)
- {
- short kind;
- Handle h;
- Rect r;
-
- GetDItem(dialog,item,&kind,&h,&r);
- if(state==hide)
- HideControl((ControlHandle)h);
- else
- ShowControl((ControlHandle)h);
-
- }
-
- char *pStrcat(s,t)
- unsigned char *s, *t;
- {
- unsigned char *s2;
- short tLen;
-
- s2 = s + *s;
- *s += (tLen = *t);
- for (++tLen; --tLen; s2[tLen] = t[tLen]);
- return (s);
- }
-
- char *pStrcpy(s,t)
- unsigned char *s, *t;
- {
- short tLen;
-
- for (tLen = *t + 1; tLen--; s[tLen] = t[tLen]);
- return (s);
- }
-
- char * PathNameFromDirID(long DirID, short vRefNum, char *s)
- {
- CInfoPBRec block;
- Str255 directoryName;
- int err;
-
-
- *s = 0;
-
- block.dirInfo.ioNamePtr = &directoryName;
- block.dirInfo.ioDrParID = DirID;
-
- do {
- block.dirInfo.ioVRefNum = vRefNum;
- block.dirInfo.ioFDirIndex = -1;
- block.dirInfo.ioDrDirID = block.dirInfo.ioDrParID;
-
- err = PBGetCatInfo(&block,false);
- if(err){
- s[0]=0;
- return((char *)-1);
- }
- if (gHaveAUX) {
- if (directoryName[1] != '/')
- /* If this isn't root (i.e. '/'), append a slash ('/') */
- pStrcat(&directoryName,"\p/");
- } else
- /* Append a Macintosh style colon (':') */
- pStrcat(&directoryName,"\p:");
- pStrcat(&directoryName,s);
- pStrcpy(s,&directoryName);
- } while (block.dirInfo.ioDrDirID != 2);
-
- return(s);
- }
-
- char * PathNameFromWD(long vRefNum, char *s)
- {
-
- WDPBRec myBlock;
- int err;
-
- /*
- /* PBGetWDInfo has a bug under A/UX 1.1. If vRefNum is a real vRefNum
- /* and not a wdRefNum, then it returns garbage. Since A/UX has only 1
- /* volume (in the Macintosh sense) and only 1 root directory, this can
- /* occur only when a file has been selected in the root directory (/).
- /* So we look for this and hardcode the DirID and vRefNum. */
-
- if (gHaveAUX && (vRefNum == -1))
- return(PathNameFromDirID(2,-1,s));
-
- myBlock.ioNamePtr = nil;
- myBlock.ioVRefNum = vRefNum;
- myBlock.ioWDIndex = 0;
- myBlock.ioWDProcID = 0;
-
- /* Change the Working Directory number in vRefnum into a real vRefnum */
- /* and DirID. The real vRefnum is returned in ioVRefnum, and the real */
- /* DirID is returned in ioWDDirID. */
-
- err=PBGetWDInfo(&myBlock,false);
- if(err){
- s[0]=0;
- return((char *)-1);
- }
-
- return(PathNameFromDirID(myBlock.ioWDDirID,myBlock.ioWDVRefNum,s));
- };
-
- long GetDirID(long vRefNum)
- {
- WDPBRec myBlock;
- int err;
-
- /*
- /* PBGetWDInfo has a bug under A/UX 1.1. If vRefNum is a real vRefNum
- /* and not a wdRefNum, then it returns garbage. Since A/UX has only 1
- /* volume (in the Macintosh sense) and only 1 root directory, this can
- /* occur only when a file has been selected in the root directory (/).
- /* So we look for this and hardcode the DirID and vRefNum. */
-
- if (gHaveAUX && (vRefNum == -1))
- return(2);
-
- myBlock.ioNamePtr = nil;
- myBlock.ioVRefNum = vRefNum;
- myBlock.ioWDIndex = 0;
- myBlock.ioWDProcID = 0;
-
- /* Change the Working Directory number in vRefnum into a real vRefnum */
- /* and DirID. The real vRefnum is returned in ioVRefnum, and the real */
- /* DirID is returned in ioWDDirID. */
-
- err=PBGetWDInfo(&myBlock,false);
- if(err){
- return((long)-1);
- }
-
- return(myBlock.ioWDDirID);
- }
-
- short GetRealRefNum(long vRefNum)
- {
- WDPBRec myBlock;
- int err;
- char debug[100];
-
- /*
- /* PBGetWDInfo has a bug under A/UX 1.1. If vRefNum is a real vRefNum
- /* and not a wdRefNum, then it returns garbage. Since A/UX has only 1
- /* volume (in the Macintosh sense) and only 1 root directory, this can
- /* occur only when a file has been selected in the root directory (/).
- /* So we look for this and hardcode the DirID and vRefNum. */
-
- if (gHaveAUX && (vRefNum == -1))
- return(-1);
-
- myBlock.ioNamePtr = nil;
- myBlock.ioVRefNum = vRefNum;
- myBlock.ioWDIndex = 0;
- myBlock.ioWDProcID = 0;
-
- /* Change the Working Directory number in vRefnum into a real vRefnum */
- /* and DirID. The real vRefnum is returned in ioVRefnum, and the real */
- /* DirID is returned in ioWDDirID. */
-
- err=PBGetWDInfo(&myBlock,false);
- if(err){
- sprintf(debug,"PBGetWDInf error: %d",err);
- debugstr(debug);
- }
-
- return(myBlock.ioWDVRefNum);
- }
-
-
- int Log2(int v)
- {
- int x;
-
- if(v<=0)
- return(0);
-
- for(x=0;(v-1)>>x;x++);
- return(x);
- }
-
-
- #define TopLeft(aRect) (* (Point *) &(aRect).top)
- #define BotRight(aRect) (* (Point *) &(aRect).bottom)
-
-
- void GetGlobalRect (WindowPtr window, Rect *globalRect)
- {
- GrafPtr savePort;
-
- GetPort(&savePort);
- SetPort(window);
- *globalRect = window->portRect;
- LocalToGlobal(&TopLeft(*globalRect));
- LocalToGlobal(&BotRight(*globalRect));
- SetPort(savePort);
- }
-
-
-